package com.irs.service.impl;

import com.irs.mapper.BuildingVideoMapper;
import com.irs.pojo.BuildingVideo;
import com.irs.service.BuildingVideoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class BuildingVideoServiceImpl implements BuildingVideoService {

    @Resource
    private BuildingVideoMapper buildingVideoMapper;

    public int insert1(BuildingVideo pojo){
        return buildingVideoMapper.insert(pojo);
    }

    public int insertList(List< BuildingVideo> pojos){
        return buildingVideoMapper.insertList(pojos);
    }

    public List<BuildingVideo> select(BuildingVideo pojo){
        return buildingVideoMapper.select(pojo);
    }

    public int update1(BuildingVideo pojo){
        return buildingVideoMapper.update(pojo);
    }


    public List<BuildingVideo> getAll() {
        //实现获取所有的视频资源
        //需要去访问dao
        List< BuildingVideo> videos = buildingVideoMapper.selectAll();
        return videos;
    }

    @Override
    public String del(String id) {
        //考虑数据库中是否存在该id的视频资源
        //如果存在  执行删除操作   如果不存在 返回错误信息
        BuildingVideo video = buildingVideoMapper.selectByPrimaryKey(id);
        if (video != null){
            //执行删除操作
            int i = buildingVideoMapper.deleteByPrimaryKey(id);
            if (i == 1){
                return "video删除成功";
            }else {
                return "数据库操作异常！";
            }
        }else {
            //返回错误信息
            return "该数据不存在";
        }
    }

    @Override
    public String insert( BuildingVideo video_msg) {
        //需要添加一个id
        String id = UUID.randomUUID().toString();//产生一个随机的id
        //System.out.println(id);
        //将id设置到video中
        video_msg.setId(id);
        //执行插入操作
        int i = buildingVideoMapper.insert(video_msg);
        if (i==1){
            return "succcess";

        }else {
            return "error";
        }
    }

    @Override
    //更改video信息
    public void update( BuildingVideo video_msg) {
        //捕获异常  有异常就捕获错误提示信息   无错误就直接执行
        try {
            buildingVideoMapper.updateByPrimaryKey(video_msg);
            System.out.println(video_msg);
        }catch (Exception e){

        }

    }

}
